# 一位数码管 显示
''' 
使用：
digit1 = Digit({
    'a':21,
    'b':22,
    'c':4,
    'd':2,
    'e':15,
    'f':19,
    'g':18
})
digit1.showNum(1)
'''
class Digit:
    # Pin 对象保存 {a:Pin(21),...}
    pins = {}
    # 数字对应的二极管显示
    numMap = ['abcdef','bc','abged','abgcd','fgbc','afgcd','afgcde','abc','abcdefg','abcdfg'] 
    #pinNum 格式 {a:18,b:19}，IO标识
    def __init__(self, pinNum):
        self.pins = {key:Pin(pinNum[key],Pin.OUT) for key in pinNum}
    #num 0-9
    def showNum(self,num):
        numM = self.numMap[num]
        #先把全部关了
        for pin in self.pins:
            self.pins[pin].off()
        #再将数字对应的二极管显示
        for char in numM:
            self.pins[char].on()
    # 全部关闭
    def clear(self):
        for pin in self.pins:
            self.pins[pin].off()
